﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;

namespace ImbedLibrary
{

    /// <summary>
    /// 读取委托方法
    /// </summary>
    /// <typeparam name="T">泛型实体</typeparam>
    /// <param name="list">集合泛型<实体></param>
    /// <param name="reader">数据读取器</param>
    public delegate void IDataRender<T>(IList<T> list, IDataReader reader);

    public abstract class SQLBaseHelper
    {
        public SQLBaseHelper() { }

        public SQLBaseHelper(string path)
        {
            this.connString = path;
        }

        /// <summary>
        /// 连接字符串
        /// </summary>
        public string connString = string.Empty;

        /// <summary>
        /// 执行sql语句返回执行结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="render"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public abstract IList<T> ExecuteReader<T>(string sql, IDataRender<T> render, params IDataParameter[] param);

        /// <summary>
        /// 执行sql语句返回执行结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="render"></param>
        /// <returns></returns>
        public abstract IList<T> ExecuteReader<T>(string sql, IDataRender<T> render);

        /// <summary>
        /// 执行sql语句返回执行结果
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        public abstract DataSet ExecuteReader(string sql);

        /// <summary>
        /// 执行sql语句返回影响行数
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public abstract int ExecuteNonQuery(string sql);

        /// <summary>
        /// 执行sql语句返回影响行数
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public abstract int ExcuteScalar(string sql, params IDataParameter[] param);

        /// <summary>
        /// 获取表中的字段名称
        /// </summary>
        /// <param name="name">表名</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public abstract List<string> GetTableField(string name, string type);
    }
}
